<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>人脉圈</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css"/>
    <link rel="stylesheet" type="text/css" href="../css/mui.min.css"/>
    <style>
        body {
            font-size: 14px;
        }

        header {
            background: #327afa;
            padding: 12px;
            position: fixed;
            width: 100%;
            z-index: 99;
            top: 0;
        }

        .hyHeader .aui-list-view {
            margin-bottom: 0px;
        }

        .contain {
            background: #ededed;
        }

        .aui-tab-nav {
            width: 50%;
            margin: 0 auto;
            font-size: 13px;
            border: 1px solid #fff;
            height: 35px;
            line-height: 35px !important;
        }

        .aui-tab-nav.aui-tab-border {
            border-color: #fff;
        }

        .aui-tab-nav.aui-tab-border li {
            height: 35px;
            line-height: 35px !important;
            color: #fff;
            background: transparent;
        }

        .aui-list-view {
            margin-bottom: 8px;
        }

        header .aui-tab-nav.aui-tab-border li.active {
            color: #327afa;
            background: #fff;
            border-bottom: 2px #327afa solid;
        }

        .header-icon {
            position: absolute;
            top: 50%;
            margin-top: -16px;
            right: 15px;
            color: #fff;
        }

        .header-icon .aui-icon-add {
            margin-right: 8px;
        }

        .header-icon .aui-iconfont {
            font-size: 20px;
        }

        .wdheader img {
            width: 100%;
        }

        .wdheader {
            display: none;
        }

        .aui-list-view i.aui-iconfont.aui-icon-location {
            color: #ff7b06;
            margin-right: 0;
            padding: 0;

        }

        .pingluns i.aui-iconfont {
            margin: 0;
        }

        .aui-list-view.weizhi {
            background: none;
            font-size: 13px;
            margin-top: 8px;
            color:#888;
        }

        .weizhi .aui-list-view-cell {
            margin-bottom: 0;
            background: none;
            padding: 0px 15px;
        }

        .weizhi .aui-list-view-cell > a {
            margin: 0px -15px;
        }

        .weizhi .aui-list-view-cell:after {
            border: none;
        }

        .weizhi .aui-arrow-right:after {
            content: "\e6a4";
            font-size: 18px;
        }

        /*动态*/

        .dongtai ul {
            background: #ededed;
        }

        .dongtai .aui-list-view .aui-img-object {
            max-width: 10%;
            /*height: 40px;*/
            float: left;
        }

        .dongtai .dongtaiContent {
            float: right;
            width: 88%;
        }

        .aui-list-view .aui-img-object {
            height: auto;
        }

        .aui-list-view .aui-img-object.aui-pull-left {
            margin-right: 2%;
        }

        .dongtai .aui-list-view-cell {
            margin-bottom: 6px;
            background: #fff;
            margin-top: 8px;
        }

        .aui-img-body {
            float: left;
            width: 100%;
        }

        .remenType ul {
            background: #fff;
        }

        .aui-list-view:after {
            border: none;
        }

        .type {
            font-size: 11px;
            background: #327afa;
            color: #fff;
            padding: 0px 5px;
            margin-bottom: 4px;
        }

        .title {
            width: 100%;
            margin:6px;
            margin-top:0;
            word-wrap:break-word;
        }

        .content img.type1,
        .content img.type2{
            max-height: 200px;
            max-width: 80%;
            float: left;
        }
        .content img.type1{
            /*width:90%;*/
        }
        .content img.type2{
            width:45%;
            margin-right:2%;
        }
        .content .type3,
        .content .type4{
            background-color: #eee;
            background-size: cover;
            height:135px;
            margin-right:2%;
            margin-top: 3px;
            float: left;

            width: 31%;
            height:80px;
        }
        .content .type4{
            width: 45%;
        }

/*        .img-item {
            background-color: #eee;
            background-size: cover;
            height:135px;
            margin-right:2%;
            margin-top: 3px;
            float: left;
        }
        .img-item.type1{
            width:82%;
        }
        .img-item.type2{
            width:41%;
        }
        .img-item.type3{
            width:31%;
        }*/

/*        .content img {
            width: 31%;
            margin-left: 2%;
            float: left;
            margin-top: 8px;
        }*/

        .companyName {
            color: #327afa;
            width: 74%;
            margin-left:5px;
            display: inline-block;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
        .deletePost{
            color: #327afa;
            font-size:12px;
            margin-left: 10px;
        }

        .pingluns {
            width: 100%;
            float: left;
            padding-left: 12%;
            margin-top: 5px;
            height: 32px;
            line-height: 32px;
        }

        .time {
            font-size: 12px;
            margin-left: 2%;
            color: #999;
        }

        .aui-icon-commentfill {
            color: #327afa !important;
        }

        .pinglun {
            overflow: hidden;
            position: relative;
            width: 140px;
            height: 40px;
        }

        .pinglun .commentLayer {
            background: rgba(0, 0, 0, .7);
            color: #fff;
            border-radius: 4px;
            font-size: 12px;
            right: -100%;
            z-index:20;
            position: absolute;
        }
        .pinglun .commentLayer i,
        .pinglun .commentLayer span{
            padding: 10px 10px !important;
        }

        .pinglun i:before {
            margin-right: 5px;
        }

        .colorB {
            color: #327afa;
        }

        .comments {
            padding:0 10px;
            background: #e8e8e8;
            float: left;
            font-size: 13px;
            margin-left: 14%;
        }

        .zan {
            padding: 5px 0;
        }

        .zan.aui-icon-like:before {
            position: absolute;
            left: -4px;
            font-size: 15px;
        }

        .comment-list {
            padding: 5px 0;
            background: none !important;
            word-wrap:break-word;
        }

        /*显示评论和赞*/
        .showComment {
            animation: showComment 0.5s forwards;
        }

        @keyframes showComment0 {
            from {
                right: -100%;
            }
            to {
                right: 00%;
            }
        }

        /*隐藏评论和赞*/
        .hideComment {
            animation: hideComment 0.5s forwards;
        }

        @keyframes hideComment0 {
            from {
                right: 00%;
            }
            to {
                right: -100%;
            }
        }

        /*类别样式*/
        .contain-left {
            width: 25%;
            text-align: center;
            float: left;
            font-size: 12px;
        }

        .contain-left .aui-list-view-cell {
            padding: 3px 0;
            margin: 0;
        }

        .contain-left .active {
            color: #fa5354;
            border: none;
            background: #f3f3f2
        }

        .contain-right {
            /*padding: 12px;*/
            width: 75%;
            float: left;
        }

        .other {
            /*display: none;*/
            text-align: center;
        }

        .other .aui-list-view-cell {
            padding: 0px 0;
        }

        .other .aui-list-view-cell:after {
            border: none;
        }

        .other li {
            border: 1px solid #d5d5d5;
            border-radius: 3px;
            float: left;
            margin-left: 5%;
            font-size: 12px;
            margin-top: 8px;
            line-height: 30px;
            height:30px;
            color:#666;
        }

        /*分类*/
        .renmaiType {
            position: relative;
            font-size: 14px;
            background: #fff;
            /*overflow: hidden;*/
            /*padding: 8px 0;*/
            height: 40px;
            line-height: 40px;
            margin-top: 8px;
            padding-left:5px;
        }
        .renmaiType .aui-icon-unfold{
            font-size:11px;
            padding-left: 4px;
        }

        .renmaiType > li.active {
            color: #327afa;
            font-weight: bold;
        }

        .renmaiType > li.active i.aui-icon-unfold:before {
            content: "\e6de";
        }

        .contain {
            display: none;
            position: absolute;
            left:0;top: 100%;
            z-index: 99;
            background: #f3f3f2;
            width: 100%;
        }

        .close {
            width: 100%;
            float: left;
            background: #eee;
            color:#666;
        }

        .close i {
            position: relative;
            font-size: 12px;
            top: 7px;
        }

        .close i:before {
            position: absolute;
            top: -28px;
            left: 2px;
            font-size: 18px;
        }
        .wodeRenMai {
            display: none;
        }
        .added{
            background: #2ecc71 !important;
        }
    </style>
</head>
<body>
<div id="commentMask" style="width: 100%;height: 100%;z-index: 9999;position: fixed;left: 0;top:0;display: none;"></div>
<div class="contains">
    <!-- 我的人脉头部 -->
    <div class="wdheader"><img src="../image/renmai.jpg"></div>
    <!-- 行业人脉头部 -->
    <div class="hyHeader">
        <ul class="aui-list-view">
            <li class="aui-list-view-cell" tapmode onclick="go2Nearby();">
                <a class="aui-arrow-right">
                    <i class="aui-iconfont aui-icon-location "></i>
                    附近人脉
                </a>
            </li>
        </ul>
        <ul class="renmaiType" style="display: none;">
            <li tapmode class="aui-col-xs-3 aui-text-center h5">全部分类<i class="aui-iconfont aui-icon-unfold"></i></li>
            <li tapmode class="aui-col-xs-3 aui-text-center h5">品牌商<i class="aui-iconfont aui-icon-unfold"></i></li>
            <li tapmode class="aui-col-xs-3 aui-text-center h5">选择地区<i class="aui-iconfont aui-icon-unfold"></i></li>
            <li tapmode class="aui-col-xs-3 aui-text-center h5">智能排序<i class="aui-iconfont aui-icon-unfold"></i></li>
            <div class="contain aui-border-t aui-border-b" style="display: none;">
                <div class="contain-left">
                    <ul class="aui-list-view">
                        <li class="aui-list-view-cell aui-border-t  active">
                            全部分类
                        </li>
                        <li class="aui-list-view-cell aui-border-l aui-border-r">
                            家纺
                        </li>
                        <li class="aui-list-view-cell aui-border-l aui-border-r">
                            服装
                        </li>
                        <li class="aui-list-view-cell aui-border-l aui-border-r">
                            天然原料
                        </li>
                    </ul>
                </div>
                <div class="contain-right">
                    <div class="tuijian">
                        <!-- 非热门 -->
                        <div class="other">
                            <ul>
                                <li class="aui-list-view-cell aui-img ">
                                    <div class="aui-img-body">
                                        &nbsp;&nbsp;大象服饰大象服饰&nbsp;&nbsp;
                                    </div>
                                </li>
                                <li class="aui-list-view-cell aui-img ">
                                    <div class="aui-img-body">
                                        &nbsp;&nbsp;大象服饰&nbsp;&nbsp;
                                    </div>
                                </li>
                                <li class="aui-list-view-cell aui-img ">
                                    <div class="aui-img-body">
                                        &nbsp;&nbsp;大象服饰&nbsp;&nbsp;
                                    </div>
                                </li>
                                <li class="aui-list-view-cell aui-img ">
                                    <div class="aui-img-body">
                                        &nbsp;&nbsp;大象服饰&nbsp;&nbsp;
                                    </div>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
                <div class="close aui-text-center">
                    <!-- 收起 -->
                    <i class="aui-iconfont aui-icon-fold">收起</i>
                </div>
            </div>
        </ul>
        <ul class="aui-list-view weizhi">
            <li class="aui-list-view-cell" onclick="updateLocation(1);">
                <a class="aui-arrow-right">
                    当前：<span id="locationDesc">未授权定位</span>
                </a>
            </li>
        </ul>
    </div>

    <!-- 行业人脉 -->
    <div class="dongtai hangyeRenMai">
        <ul class="aui-list-view" id="hangyeList">
        </ul>
    </div>
    <!-- 我的人脉 -->
    <div class="dongtai wodeRenMai">
        <ul class="aui-list-view " id="haoyouList">
        </ul>
    </div>
</div>
</body>
<script id="post-hangye-template" type="text/x-dot-template">
    {{ for(var i in it){ }}
    <li class="aui-list-view-cell aui-img post-item" data-id="{{=it[i].id}}">
        <img class="aui-img-object aui-pull-left" src="{{=it[i].company.thumb}}" onclick="go2User({{=it[i].company.userid}})">
        <div class="dongtaiContent">
            <div class="aui-img-body">
                <span class="companyName" onclick="go2User({{=it[i].company.userid}})">{{=it[i].company.company}}</span>
                {{? it[i].userid!=myUid}}
                {{? it[i].relation==2}}
                <div class="type aui-pull-right" onclick="openchat({{=it[i].company.userid}},'{{=it[i].company.thumb}}','{{=it[i].company.company}}')">聊天</div>
                {{?? it[i].relation==1}}
                <div class="type aui-pull-right added friendBtn" onclick="delFriend(this)" data-userid="{{=it[i].company.userid}}">已加人脉</div>
                {{??}}
                <div class="type aui-pull-right friendBtn" onclick="addFriend(this)" data-userid="{{=it[i].company.userid}}">加为人脉</div>
                {{?}}
                {{?}}
            </div>
            {{? it[i].text != null }}
            <div class="title aui-pull-left">{{=it[i].text}}</div>
            {{?}}
            {{? it[i].pic.length }}
            <div class="content aui-clearfix">
               {{? it[i].pic.length==1 }}
               <img class="content-img type1" src="{{=it[i].pic[0].url}}" data-src="{{=it[i].pic[0].url}}" />
               {{?? it[i].pic.length==2 }}
               <img class="content-img type2" src="{{=it[i].pic[0].url}}" data-src="{{=it[i].pic[0].url}}" />
               <img class="content-img type2" src="{{=it[i].pic[1].url}}" data-src="{{=it[i].pic[1].url}}" />
               {{?? it[i].pic.length==4 }}
               <div class="content-img type4" style="background-image: url({{=it[i].pic[0].url}});" data-src="{{=it[i].pic[0].url}}"></div>
               <div class="content-img type4" style="background-image: url({{=it[i].pic[1].url}});" data-src="{{=it[i].pic[1].url}}"></div>
               <div class="content-img type4" style="background-image: url({{=it[i].pic[2].url}});" data-src="{{=it[i].pic[2].url}}"></div>
               <div class="content-img type4" style="background-image: url({{=it[i].pic[3].url}});" data-src="{{=it[i].pic[3].url}}"></div>
               {{??}} 
               {{ for(var j in it[i].pic){ }}
               <div class="content-img type3" style="background-image: url({{=it[i].pic[j].url}});" data-src="{{=it[i].pic[j].url}}"></div>
               {{ } }}
               {{?}}
            </div>
            {{?}}
        </div>
    </li>
    {{ } }}
</script>
<script id="post-haoyou-template" type="text/x-dot-template">
    {{ for(var i in it){ }}
    <li class="aui-list-view-cell aui-img post-item" data-id="{{=it[i].id}}">
        <img class="aui-img-object aui-pull-left" src="{{=it[i].company.thumb}}" onclick="go2User({{=it[i].company.userid}})">
        <div class="dongtaiContent">
            <div class="aui-img-body">
                <span class="companyName" onclick="go2User({{=it[i].company.userid}})">{{=it[i].company.company}}</span>
                {{? it[i].company.userid!=myUid}}
                <div class="type aui-pull-right" tapmode onclick="openchat({{=it[i].company.userid}},'{{=it[i].company.thumb}}','{{=it[i].company.company}}')">聊天</div>
                {{?}}
            </div>
            {{? it[i].text != null }}
            <div class="title aui-pull-left">{{=it[i].text}}</div>
            {{?}}
            {{? it[i].pic.length }}
            <div class="content aui-clearfix">
               {{? it[i].pic.length==1 }}
               <img class="content-img type1" src="{{=it[i].pic[0].url}}" data-src="{{=it[i].pic[0].url}}" />
               {{?? it[i].pic.length==2 }}
               <img class="content-img type2" src="{{=it[i].pic[0].url}}" data-src="{{=it[i].pic[0].url}}" />
               <img class="content-img type2" src="{{=it[i].pic[1].url}}" data-src="{{=it[i].pic[1].url}}" />
               {{?? it[i].pic.length==4 }}
               <div class="content-img type4" style="background-image: url({{=it[i].pic[0].url}});" data-src="{{=it[i].pic[0].url}}"></div>
               <div class="content-img type4" style="background-image: url({{=it[i].pic[1].url}});" data-src="{{=it[i].pic[1].url}}"></div>
               <div class="content-img type4" style="background-image: url({{=it[i].pic[2].url}});" data-src="{{=it[i].pic[2].url}}"></div>
               <div class="content-img type4" style="background-image: url({{=it[i].pic[3].url}});" data-src="{{=it[i].pic[3].url}}"></div>
               {{??}} 
               {{ for(var j in it[i].pic){ }}
               <div class="content-img type3" style="background-image: url({{=it[i].pic[j].url}});" data-src="{{=it[i].pic[j].url}}"></div>
               {{ } }}
               {{?}}
            </div>
            {{?}}
        </div>
        <div class="pingluns">
            <span class="time">{{=formatMsgTime(it[i].addtime)}}</span>
            {{? it[i].userid==myUid }}
            <span class="deletePost">删除</span>
            {{?}}
            <i class="aui-iconfont aui-icon-commentfill aui-pull-right comment-icon" style="padding:0px 10px;"></i>
            <div class="pinglun aui-pull-right ">
                <div class="commentLayer showComment">
                    {{ var hasLiked=false; }}
                    {{for(var k in it[i].likeuser){ }}
                    {{? it[i].likeuser[k].userid==myUid }}
                    {{ hasLiked=true; }}
                    {{?}}
                    {{ } }}
                    {{? hasLiked }}
                    <i class="aui-iconfont aui-icon-appreciate " tapmode style="display: none;">赞</i>
                    <span class="cancelLike" style="font-size: 15px;padding-left:5px;">取消赞</span>
                    {{??}}
                    <i class="aui-iconfont aui-icon-appreciate " tapmode>赞</i>
                    <span class="cancelLike" style="font-size: 15px;padding-left:5px;display: none;">取消赞</span>
                    {{?}}
                    
                    <i class="aui-iconfont aui-icon-comment " tapmode>评论</i>
                </div>
            </div>
        </div>
        <div class="comments" style="width: 81%;display:{{? it[i].comment.length||it[i].likeuser.length }}block{{??}}none{{?}};" data-id="{{=it[i].id}}">
            <div class="zan colorB"  style="display: {{? it[i].likeuser.length }}block{{??}}none{{?}};" >
                <i class="aui-iconfont aui-icon-appreciate aui-text-info"></i>
                {{ for (var l in it[i].likeuser){ }} <span class="likeuser-item" data-value="{{=it[i].likeuser[l].company.userid}}" onclick="go2User({{=it[i].likeuser[l].company.userid}})">{{=it[i].likeuser[l].company.company}} {{? l!=it[i].likeuser.length-1}},{{?}} {{ } }}
                </span>
            </div>
            <ul class="comment-list  {{? it[i].comment.length&&it[i].likeuser.length }} aui-border-t {{?}}" style="display: {{? it[i].comment.length }}block{{??}}none{{?}};">
            {{ for (var k in it[i].comment){ }}
                <li data-id="{{=it[i].comment[k].id}}" data-userid="{{=it[i].comment[k].company.userid}}"><span class="colorB"><span onclick="go2User({{=it[i].comment[k].company.userid}})">{{=it[i].comment[k].company.company}}</span>：</span>{{=transText(it[i].comment[k].text)}}</li>
            {{ } }}
            </ul>
        </div>
    </li>
    {{ } }}
</script>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript" src="../script/myInfo.js"></script>
<script type="text/javascript" src="../script/jquery-1.11.3.js"></script>
<script type="text/javascript" src="../script/mui.js"></script>
<script type="text/javascript" src="../script/doT.min.js"></script>
<script type="text/javascript">
    var imgBase64,isLock=false;
    window.postType=1;
    var myUid;
    var myName;
    var page=1;
    var rong;
    var latitude,longitude;
    var emotionData;
    var defaultAvatar;
    apiready = function () {
        api.parseTapmode();
        // getInfo();

        //发布完成后
        api.addEventListener({
            name: 'publishPostDone'
        }, function(ret, err) {
            headerChange(2,true);
        });

        //下拉刷新
        api.setRefreshHeaderInfo({
            visible : true,
            loadingImg : 'widget://image/ptr_pull.png',
            bgColor : '#efeff4',
            textColor : '#959595',
            textDown : '下拉刷新',
            textUp : '松开刷新',
            showTime : true
        }, function(ret, err) {
            page=1;
            isLock=false;
            loadData();
        });

        // 监听是否达到底部上拉加载
        api.addEventListener({
            name : 'scrolltobottom'
        }, function(ret, err) {
            page++;
            if (!isLock)loadData(page);
        });

        //监听登陆成功
        api.addEventListener({
            name: 'reGetMyInfo'
         }, function (ret) {
            $('#hangyeList,#haoyouList').html('');

            if (ret && ret.value) {
                getLocation(function(ret,err){
                    if(ret.result){
                        //获取位置信息成功
                        latitude=ret.result.location.lat;
                        longitude=ret.result.location.lng;

                        getStorageAll();
                        ajaxRequest('Member/updateLocation?username='+user_name, 'post', {latitude:latitude,longitude:longitude}, function (ret, err) {
                            if(ret.status==1){
                            }
                        });
                    }
                });
            }
         });

        //更新位置描述
        updateLocation();

        //表情图片处理
        getImgsPaths("widget://image/emotion", function(emotion) {
            emotionData = emotion;
        });
    }

    //加载数据
    function loadData(toPage){
        toPage=toPage?toPage:page;

        if(toPage==1)api.refreshHeaderLoading();

        getStorageAll();
        var data = {};
        var url=postType==1?('Post/all?username='+user_name+'&page='+toPage):('Post/friend?username='+user_name+'&page='+toPage);
        myUid=user_id;
        myName=nick_name;
        if(!isLock){
            isLock = true;
            ajaxRequest(url, 'get', data, function (ret, err) {
                api.refreshHeaderLoadDone();            

                if (ret.status == 1) {
                    var tpl = $api.byId(postType==1?'post-hangye-template':'post-haoyou-template').text;
                    var tempFn = doT.template(tpl);

                    var $contentEle=postType==1?$('#hangyeList'):$('#haoyouList');
                    $contentEle.show();
                    if (toPage > 1) {
                        if(!$.trim(ret.msg)){
                            isLock=true;
                            return;
                        }
                        $contentEle.append(tempFn(ret.msg));
                    } else {
                        $contentEle.html(tempFn(ret.msg));
                    }
                } else {
                    api.toast({
                        msg: ret.msg,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
                isLock=false;
            });
        }
    }

    // 头部tab标签切换
    function headerChange(dataType,isForce) {
        page=1;
        isLock=false;
        if (dataType == "1") {
            $(".hyHeader").css({"display": "block"});
            $(".hangyeRenMai").css({"display": "block"});
            $(".wdheader").css({"display": "none"});
            $(".wodeRenMai").css({"display": "none"});
            postType=1;

            onMenuTapped();
        } else {
            $(".hyHeader").css({"display": "none"});
            $(".hangyeRenMai").css({"display": "none"});
            $(".wdheader").css({"display": "block"});
            $(".wodeRenMai").css({"display": "block"});
            postType=2;

            if((!$('#haoyouList li').length&&!isLock)||isForce){
                loadData();
            }
        }
    }

    $(document).ready(function(){
        // 大类别的切换
        $('.renmaiType').delegate('.aui-col-xs-3','click',function(){
            if($(this).hasClass("active")) {
                $(this).removeClass("active");
                $(".contain").css({"display": "none"})
            } else {
                $(".contain").css({"display": "block"})
                $(this).parent().children("li").removeClass("active");
                $(this).addClass("active");
            }
        });
       // 大类别收起
        $('body').delegate('.close','click', function () {
            $(".renmaiType .aui-col-xs-3").removeClass("active");
            $(".contain").css({"display": "none"})
        });
        // 小类别的切换样式
        $('body').delegate(".contain li", "click", function () {
            $(this).parent().find("li").removeClass("active").addClass("aui-border-l").addClass("aui-border-r");
            $(this).addClass("active").removeClass("aui-border-l").removeClass("aui-border-r");
        });


        //单击评论图标，显示隐藏赞和评论
        $('#haoyouList').undelegate('.comment-icon').delegate(".comment-icon", "click", function () {
            var $this=$(this);
            var $commentLayer = $(this).parent().find(".commentLayer");
            getStorageAll();
            
            if ($commentLayer.hasClass("showComment")) {
                $commentLayer.removeClass("showComment");
                $commentLayer.addClass("hideComment");
                $commentLayer.animate({"right": "-100%"}, 150,function(){
                    $commentLayer.find('i,span').unbind('click').bind('click',function(e){
                        e.stopPropagation();
                        var $comments=$(this).closest('.pingluns').siblings('.comments');
                        var postid=$comments.attr('data-id');
                        if($(this).hasClass('aui-icon-appreciate')){
                            //like
                            var $this=$(this);

                            //show html result
                            $this.hide().siblings('.cancelLike').show();
                            $comments.show().find('.zan').show();

                            var $myItem=$comments.find('.likeuser-item[data-value="'+myUid+'"]');
                            if($myItem.length)return;

                            $comments.find('.aui-icon-appreciate').after('<span class="likeuser-item" data-value="'+myUid+'" onclick="go2User('+myUid+')">'+myName+($comments.find('.likeuser-item').length?',':'')+'</span>');  

                            //request
                            ajaxRequest('Post/like?username='+user_name, 'post', {postid:postid}, function (ret, err) {
                                if (ret.status == 1) {

                                } else {
                                    api.toast({
                                        msg: ret.msg,
                                        duration: 2000,
                                        location: 'bottom'
                                    })
                                }
                            });

                        }else if($(this).hasClass('cancelLike')){
                            //unlike
                            $this=$(this);

                            //show html result
                            $this.hide().siblings('.aui-icon-appreciate').show();

                            var $myItem=$comments.find('.likeuser-item[data-value="'+myUid+'"]');
                            $myItem.remove();

                            if(!$comments.find('.likeuser-item').length)$this.closest('.pingluns').siblings('.comments').find('.zan').hide();

                            //request
                            ajaxRequest('Post/unlike?username='+user_name, 'post', {postid:postid}, function (ret, err) {
                                if (ret.status == 1) {

                                } else {
                                    api.toast({
                                        msg: ret.msg,
                                        duration: 2000,
                                        location: 'bottom'
                                    })
                                }
                            });
                        }else{
                            //comment
                            var $commentUl=$comments.find('.comment-list');

                            var UIChatBox = api.require('UIChatBox');
                            UIChatBox.open({
                                placeholder: '输入评论内容',
                                autoFocus:true,
                                maxRows: 4,
                                emotionPath: '../image/uichatbox/emotion',
                                texts: {
                                    sendBtn:{
                                        title:"发送"
                                    }
                                },
                                styles: {
                                    inputBar: {
                                        borderColor: '#d9d9d9',
                                        bgColor: '#f2f2f2'
                                    },
                                    inputBox: {
                                        borderColor: '#DDDDDD',
                                        bgColor: '#FFFFFF'
                                    },
                                    emotionBtn: {
                                        normalImg: '../image/uichatbox/face1.png'
                                    }
                                }
                            }, function( ret, err ){
                                if( ret ){
                                    if(ret.eventType=='send'){
                                        var text=$.trim(ret.msg);
                                        if(!text){
                                            alert('请输入评论内容');
                                            return;
                                        }
                                        ajaxRequest('Post/addComment?username='+user_name, 'post', {postid:postid,text:text}, function (ret, err) {
                                            if (ret.status == 1) {
                                                $comments.show();
                                                $commentUl.show().append($('<li data-id="'+ret.msg.id+'"><span class="colorB"><span onclick="go2User('+myUid+')">'+myName+'</span>：</span>'+transText(text)+'</li>'));

                                                $('#commentMask').hide();
                                                UIChatBox.closeKeyboard();
                                                UIChatBox.close();
                                            } else {
                                                alert(ret.msg);
                                            }
                                        });
                                    }
                                }else{
                                     // alert( JSON.stringify( err ) );
                                }
                            });
                            $('#commentMask').show().unbind('click').bind('click',function(){
                                $(this).hide();
                                UIChatBox.closeKeyboard();
                                UIChatBox.close();
                            });


                        }
                    })
                });
            } else {
                $commentLayer.addClass("showComment");
                $commentLayer.removeClass("hideComment");
                $commentLayer.animate({"right": "0"}, 150,function(){
                    $(document).one('click',function(){
                        $this.trigger('click');
                    })
                });
            }
        });

        //单击图片效果
        $('.dongtai').delegate('.content-img','click',function(e){
            var imgUrl=$(this).attr('data-src');
            var imgList=[];
            var browseIndex=$(this).closest('.content').find('.content-img').index($(this));

            $(this).closest('.content').find('.content-img').each(function(){
                imgList.push($(this).attr('data-src'));
            })
            
            api.openWin({
                name: 'photobrowser_win',
                url: './friend/photobrowser_win.html',
                animation:{
                        type:"fade",               
                        duration:200
                    },
                pageParam:{
                    imgList:imgList,
                    browseIndex:browseIndex
                }
            });
        });

        //删除评论
        $('body').undelegate('.comment-list li').delegate('.comment-list li','click',function(){
            var $this=$(this);
            var commentid=$this.attr('data-id');
            var $comments=$this.closest('.comments');
            var commentuid=$this.attr('data-userid');
            getStorageAll();

            if(commentuid==user_id){
                api.actionSheet({
                    cancelTitle: '取消',
                    buttons: ['删除评论']
                }, function (ret, err) {
                    if(ret.buttonIndex==1){
                        ajaxRequest('Post/deleteComment?username='+user_name, 'post', {commentid:commentid}, function (ret, err) {
                            if (ret.status == 1) {
                                $this.remove();
                                if(!$comments.find('.comment-list li').length&&!$comments.find('.likeuser-item').length){
                                    $comments.hide();
                                }
                            } else {
                                api.toast({
                                    msg: ret.msg,
                                    duration: 2000,
                                    location: 'bottom'
                                })
                            }
                        });
                    }
                });
            }
        });

        //删除动态
        $('body').undelegate('.deletePost').delegate('.deletePost','click',function(){
                var $this=$(this);
                var $postItem=$this.closest('.post-item');
                var postid=$postItem.attr('data-id');
                mui.confirm("确定要删除该动态？","",["是","否"],function (e) {
                    if(e.index==0){
                        showLoading();

                        getStorageAll();
                        ajaxRequest('Post/delete?username='+user_name, 'post', {postid:postid}, function (ret, err) {
                            hideLoading();
                            if (ret.status == 1) {
                                $postItem.remove();

                                $('#hangyeList .post-item[data-id="'+postid+'"]').remove();
                            } else {
                                api.toast({
                                    msg: ret.msg,
                                    duration: 2000,
                                    location: 'bottom'
                                })
                            }
                        });
                    }
                })

        })

    });

    //读取信息
    function getInfo() {
        getStorageAll();
        if (avatar) {
            var avatarDom = $api.byId('avatar');
            $api.attr(avatarDom, 'src', '' + imgUrl + avatar + '');
        } else {
            var avatarDom = $api.byId('avatar');
            $api.attr(avatarDom, 'src', '../image/noavatar.gif');
        }
        if (nick_name) {
            var nicknameDom = $api.dom('.nickname');
            $api.text(nicknameDom, '' + nick_name + '');
        } else {
            var nicknameDom = $api.dom('.nickname');
            $api.text(nicknameDom, '游客,请登录');
        }
    }

    function go2AddPost(imageUrls){
        api.openWin({
            name:'addpost_win',
            url:'addpost_win.html',
            animation:{
                type:"movein",
                subType:"from_bottom", 
                duration:250,
                curve:'ease_in_out'
            },
            pageParam:{
                imageUrls:imageUrls
            }
        });
    }

    function onMenuTapped(){
        if(!$('#hangyeList li').length&&!isLock){
            api.refreshHeaderLoading();
        }
    }

    function changeAvatar() {
        api.actionSheet({
            title: '请选择图片',
            cancelTitle: '取消',
            buttons: ['相册选取', '魅力自拍']
        }, function (ret, err) {
            if (ret.buttonIndex == 1) {
                var UIMediaScanner = api.require('UIMediaScanner');
                UIMediaScanner.open({
                    type: 'picture',
                    column: 4,
                    classify: true,
                    max: 9,
                    sort: {
                        key: 'time',
                        order: 'desc'
                    },
                    texts: {
                        stateText: '已选择*项',
                        cancelText: '取消',
                        finishText: '完成'
                    },
                    styles: {
                        bg: '#fff',
                        mark: {
                            icon: '',
                            position: 'bottom_right',
                            size: 25
                        },
                        nav: {
                            bg: '#eee',
                            stateColor: '#000',
                            stateSize: 17,
                            cancelBg: 'rgba(0,0,0,0)',
                            cancelColor: '#327afa',
                            cancelSize: 17,
                            finishBg: 'rgba(0,0,0,0)',
                            finishColor: '#327afa',
                            finishSize: 17
                        }
                    },
                    scrollToBottom: {
                        intervalTime: -1,
                        anim: false
                    },
                    exchange: true,
                    rotation: true
                }, function(ret) {
                    if (ret) {
                        var listData=ret.list;
                        var thumbPaths=[];
                        if(listData.length){
                            showLoading();
                            for(i in listData){
                                UIMediaScanner.transPath({
                                    path: ret.list[i].path
                                }, function(ret, err) {
                                    if (ret) {
                                        thumbPaths.push(ret.path);
                                    }
                                    if(thumbPaths.length==listData.length){
                                        hideLoading();
                                        go2AddPost(thumbPaths);
                                    }
                                });
                            }
                        }
                    }
                });

                // api.getPicture({
                //     sourceType: 'library',
                //     encodingType: 'jpg',
                //     mediaValue: 'pic',
                //     destinationType: 'base64',
                //     targetWidth:500,
                //     // allowEdit: true,
                //     quality: 60,
                //     saveToPhotoAlbum: false
                // }, function (ret, err) {
                //     if (ret) {
                //         if (!ret.base64Data) {
                //             imgBase64 = '';
                //         } else {
                //             imgBase64 = ret.base64Data;
                //             go2AddPost(imgBase64);
                //             // postData();
                //         }
                //     } else {
                //         api.toast({
                //             msg: err.msg,
                //             duration: 2000,
                //             location: 'bottom'
                //         })
                //     }
                // })
            } else if (ret.buttonIndex == 2) {
                api.getPicture({
                    sourceType: 'camera',
                    encodingType: 'jpg',
                    mediaValue: 'pic',
                    destinationType: 'base64',
                    targetWidth:500,
                    // allowEdit: true,
                    quality: 60,
                    saveToPhotoAlbum: true
                }, function (ret, err) {
                    if (ret) {
                        if (!ret.base64Data) {
                            imgBase64 = '';
                        } else {
                            imgBase64 = ret.base64Data;
                            go2AddPost([imgBase64]);
                        }
                    } else {
                        api.toast({
                            msg: err.msg,
                            duration: 2000,
                            location: 'bottom'
                        })
                    }
                })
            }
        })
    }

    function postData() {
        var data = {};
        data['user_id'] = user_id;
        data['base64'] = imgBase64;
        var url = 'user_ajax.ashx?action=update_user_info';
        ajaxRequest(url, 'post', data, function (ret, err) {
            if (ret.status == 1) {
                if (ret.avatar) {
                    $api.setStorage('avatar', '' + ret.avatar + '');
                }
                //我的中心更新数据
                api.sendEvent({
                    name: 'reGetMyInfo',
                    extra: {
                        key: 'true'
                    }
                })
            } else {
                api.toast({
                    msg: ret.msg,
                    duration: 2000,
                    location: 'bottom'
                })
            }
        })
    }
    //单击加为人脉
    function addFriend(obj) {
         getStorageAll();
         var $obj=$(obj);
         var fuserid=$obj.attr('data-userid');
         ajaxRequest('Friendship/follow?username='+user_name, 'post', {fuserid:fuserid}, function (ret, err) {
            if (ret.status == 1&&(typeof ret.msg !== 'string')) {
                $('#hangyeList li .friendBtn').each(function(){
                     var addingUserid=$(this).attr('data-userid');
                     if(addingUserid==fuserid){
                        $(this).attr('onclick','javascript:delFriend(this)');
                        $(this).text("已加人脉");
                        $(this).addClass("added");
                     }
                })
            } else {
                api.toast({
                    msg: ret.msg,
                    duration: 2000,
                    location: 'bottom'
                })
            }
        })
    }

    //单击取消加人脉
    function delFriend(obj){
        getStorageAll();
         var $obj=$(obj);
         var fuserid=$obj.attr('data-userid');
         ajaxRequest('Friendship/unfollow?username='+user_name, 'post', {fuserid:fuserid}, function (ret, err) {
            if (ret.status == 1&&(typeof ret.msg !== 'string')) {
                $('#hangyeList li .friendBtn').each(function(){
                     var addingUserid=$(this).attr('data-userid');
                     if(addingUserid==fuserid){
                        $(this).attr('onclick','javascript:addFriend(this)');
                        $(this).text("加为人脉");
                        $(this).removeClass("added");
                     }
                })

            } else {
                api.toast({
                    msg: ret.msg,
                    duration: 2000,
                    location: 'bottom'
                })
            }
        })
    }

    //更新当前定位
    function updateLocation(byAction){
        if(byAction)showLoading();
        getLocation(function(ret,err){
            if(ret.result){
                latitude=ret.result.location.lat;
                longitude=ret.result.location.lng;
                var address=ret.result.formatted_address;
                if(address){
                    $('#locationDesc').text(address);
                }
            }
            if(byAction)hideLoading();
        });
    }

    function go2Nearby(){
        api.openWin({
            name: 'nearby_win',
            url: 'friend/nearby_win.html',
            vScrollBarEnabled: false,
            pageParam:{
                latitude:latitude,
                longitude:longitude
            }
        });
    }

    //表情处理
    function transText(text, imgWidth, imgHeight) {
        var imgWidth = imgWidth || 16;
        var imgHeight = imgHeight || 16;
        var regx = /\[(.*?)\]/gm;
        var textTransed = text.replace(regx, function(match) {
            if (emotionData == undefined) {
                var imgSrc = '';
            } else {
                var imgSrc = emotionData[match];
            }
            if (!imgSrc) {/* 说明不对应任何表情,直接返回即可.*/
                return match;
            }
            var img = "<img src='" + imgSrc + "' width='" + imgWidth + "' height ='" + imgHeight + "' />";
            return img;
        });
        return textTransed;
    }

    /*获取所有表情图片的名称和真实URL地址，以JSON对象形式返回。其中以表情文本为 属性名，以图片真实路径为属性值*/
    function getImgsPaths(sourcePathOfChatBox, callback) {
        var jsonPath = "widget://image/emotion" + "/emotion.json";
        //表情的JSON数组
        api.readFile({
            path : jsonPath
        }, function(ret, err) {
            if (ret.status) {
                var emotionArray = JSON.parse(ret.data);
                var emotion = {};
                for (var i in emotionArray) {
                    var emotionItem = emotionArray[i];
                    var emotionText = emotionItem["text"];
                    var emotionUrl = "../image/emotion/" + emotionItem["name"] + ".png";
                    emotion[emotionText] = emotionUrl;
                }
                /*把emotion对象 回调出去*/
                if ("function" === typeof (callback)) {
                    callback(emotion);
                }
            }
        });
    }

</script>
</html>